export type Assert<T> = (value) => value is T;

export const isArray = Array.isArray as Assert<Array<any>>;

export const isUndefined = ((value: any): boolean => value === undefined) as Assert<undefined>;

export const isObject = ((value: any): boolean => value !== null && value !== undefined && typeof value === 'object') as Assert<
  Record<string, any>
>;

// 是否是数字, 包含NaN
export const isNumber = ((value: any): boolean => typeof value === 'number') as Assert<number>;

// 是否是非NaN的数字
export const isValidNumber = ((value: any): boolean => typeof value === 'number' && !Number.isNaN(value)) as Assert<number>;

export const isString = ((value: any): boolean => typeof value === 'string') as Assert<string>;

export const isBoolean = ((value: any): boolean => typeof value === 'boolean') as Assert<boolean>;

export const isNull = ((value: any): boolean => value === null) as Assert<null>;

export const isEmpty = (value: any): boolean => value === '' || isUndefined(value) || isNull(value) || (isArray(value) && !value.length);

export function isFunction(obj: any): obj is (...args: any[]) => any {
  return typeof obj === 'function';
}
